package com.wbao.dianniu.ui;


import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wbao.dianniu.R;
import com.wbao.dianniu.utils.Utils;

/**
 * Activity基类
 * 
 * @author yejianjun
 *
 */
public class BaseFragmentActivity extends FragmentActivity implements OnClickListener {
	/** 标题左侧的返回皱键 */
	private ImageButton backBtn;
	/** 标题 */
	private TextView titleTV;
	/** 内容的布局 */
	private LinearLayout mLayoutContent;
	/** 右边文字  */
	private Button rightBtn;
	/**  右边图片按钮 */
	private ImageButton rightImageButton;
	private LinearLayout baseLinearLayout;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			Utils.setTranslucentStatus(this,true);
			SystemBarTintManager tintManager = new SystemBarTintManager(this);
			tintManager.setStatusBarTintEnabled(true);
			tintManager.setStatusBarTintResource(R.color.title_bg);// 通知栏所需颜色
		}
		setContentView(R.layout.activity_common_title);
		initBaseView();
	}
	
	private void initBaseView() {
		baseLinearLayout = (LinearLayout) findViewById(R.id.base_linear);
		backBtn = (ImageButton) findViewById(R.id.back_button);
		titleTV = (TextView) findViewById(R.id.title);
		rightBtn = (Button) findViewById(R.id.right_button);
		rightImageButton = (ImageButton) findViewById(R.id.right_imagebutton);
		mLayoutContent = (LinearLayout) findViewById(R.id.layout_content);
		backBtn.setOnClickListener(this);
		
	}

	/***
	 * 设置内容区域
	 * 
	 * @param resId
	 */

	public void setContentLayout(int resId) {
		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View contentView = inflater.inflate(resId, null);
		LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT);
		contentView.setLayoutParams(layoutParams);
		// contentView.setBackgroundDrawable(null);
		if (null != mLayoutContent) {
			mLayoutContent.addView(contentView);
		}
	}
	
	public void setContentLayout(int resId,int width, int height){
		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View contentView = inflater.inflate(resId, null);
		LayoutParams layoutParams = new LayoutParams(width,height);
		contentView.setLayoutParams(layoutParams);
		// contentView.setBackgroundDrawable(null);
		if (null != mLayoutContent) {
			mLayoutContent.addView(contentView);
		}
	}

	/***
	 * 设置内容区域
	 * 
	 * @param view
	 *            View对象
	 */

	public void setContentLayout(View view) {
		if (null != mLayoutContent) {
			mLayoutContent.addView(view);
		}
	}

	/**
	 * 获取返回的控件
	 * 
	 * @return
	 */
	public ImageButton getBackView() {
		return backBtn;
	}

	/**
	 * 
	 * 得到内容的View
	 * 
	 * @return
	 */

	public View getLayContentView() {
		return mLayoutContent;

	}

	/**
	 * 获取右边文字按钮
	 * 
	 * @return
	 */
	public Button getRightTextButton(){
		rightBtn.setVisibility(View.VISIBLE);
		return rightBtn;
	}
	
	/**
	 * 获取右边图片按钮
	 * 
	 * @return
	 */
	public ImageButton getRightImageButton(){
		rightImageButton.setVisibility(View.VISIBLE);
		return rightImageButton;
	}
	
	/**
	 * 设置背景色
	 * 
	 * @param resId
	 */
	public void setBaseBackgroundColor(int resId){
		baseLinearLayout.setBackgroundColor(resId);
	}
	
	
	/**
	 * 设置标题
	 * 
	 * @param resId
	 */
	public void setTitleName(int resId) {
		titleTV.setText(resId);
	}

	public void setTitleName(String name) {
		titleTV.setText(name);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back_button:
			finish();
			break;
		default:
			break;
		}
	}

}
